import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'
import Register from '../views/Register.vue'
import Login from '../views/Login.vue'
import Nofound from '../views/404.vue'
import Home from '../views/Home.vue'
import InfoShow from '../views/InfoShow.vue'
import FundList from '../views/FundList.vue'
import Gym from '../views/Gym.vue'
import Bag from '../views/Bag.vue'
import CityMap from '../views/CityMap.vue'
import AddGoodTypes from '../views/AddGoodTypes.vue'
import AddGood from '../views/AddGood.vue'
import AddEquipmentsTypes from '../views/AddEquipmentstypes.vue'
import AddEquipments from '../views/AddEquipments.vue'
import Gate from '../views/city/Gate.vue'
import CityBackground from '../views/city/CityBackground.vue'
import WeaponShop from '../views/city/WeaponShop.vue'
import Mission from '../views/city/Mission.vue'
import PlayerInfo from '../views/PlayerInfo.vue'
import PlayerList from '../views/Playerlist.vue'
import School from '../views/School.vue'
Vue.use(VueRouter)

const routes = [
  { path: '*',
    name: '/404', 
    component: Nofound
  },
  {
    path: '/',
    redirect: '/index',
    component: Index
  },
  {
    path: '/index',
    name: '/index',
    component: Index,
    children: [
      { path: '', component: Home },
      { path: '/home', name: 'home', component: Home },
      { path: '/gym', name: 'gym', component: Gym },
      { path: '/bag', name: 'bag', component: Bag },
      { path: '/citymap', name: 'map', component: CityMap },
      { path: '/infoshow', name: 'infoshow', component: InfoShow },
      { path: '/fundlist', name: 'fundlist', component: FundList },
      { path: '/addgoodtypes', name: 'addgoodtype', component: AddGoodTypes },
      { path: '/addgood', name: 'addgood', component: AddGood },
      { path: '/addequipmentstype', name: 'addequipmentstype', component: AddEquipmentsTypes },
      { path: '/addequipments', name: 'addequipments', component: AddEquipments },
      { path: '/gate', name: 'gate', component: Gate },
      { path: '/citybackground', name: 'citybackground', component: CityBackground },
      { path: '/weaponshop', name: 'weaponshop', component: WeaponShop },
      { path: '/mission', name: 'mission', component: Mission },
      { path: '/playerinfo', name: 'playerinfo', component: PlayerInfo },
      { path: '/playerlist', name: 'playerlist', component: PlayerList },
      { path: '/school', name: 'school', component: School },
    ]
  },
  {
    path: '/register',
    name: '/register',
    component: Register
  },
  {
    path: '/login',
    name: '/login',
    component: Login
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 路由守卫

router.beforeEach((to, from, next) => {
  const isLogin = localStorage.eleToken ? true : false;
  if(to.path == '/login' || to.path == '/register'){
    next();
  }else{
    isLogin ? next() : next('/login');
  }
});




export default router
